package com.wofish.web.controller.member;

import java.util.List;

import com.wofish.member.domain.MemberPoint;
import com.wofish.member.service.IMemberPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wofish.common.annotation.Log;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.utils.poi.ExcelUtil;

/**
 * 会员积分明细 信息操作处理
 * 
 * @author wofish
 * @date 2019-05-21
 */
@Controller
@RequestMapping("/member/memberPoint")
public class MemberPointController extends BaseController {
    private String prefix = "member/memberPoint";
	
	@Autowired
	private IMemberPointService memberPointService;
	
	@RequiresPermissions("member:memberPoint:view")
	@GetMapping()
	public String memberPoint() {
	    return prefix + "/memberPoint";
	}
	
	/**
	 * 查询会员积分明细列表
	 */
	@RequiresPermissions("member:memberPoint:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberPoint memberPoint) {
		startPage();
        List<MemberPoint> list = memberPointService.selectMemberPointList(memberPoint);
		return getDataTable(list);
	}
	



	/**
	 * 导出会员积分明细列表
	 */
	@RequiresPermissions("member:memberPoint:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberPoint memberPoint) {
    	List<MemberPoint> list = memberPointService.selectMemberPointList(memberPoint);
        ExcelUtil<MemberPoint> util = new ExcelUtil<MemberPoint>(MemberPoint.class);
        return util.exportExcel(list, "memberPoint");
    }
	
	/**
	 * 新增会员积分明细
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会员积分明细
	 */
	@RequiresPermissions("member:memberPoint:add")
	@Log(title = "会员积分明细", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MemberPoint memberPoint) {
		return toAjax(memberPointService.insertMemberPoint(memberPoint));
	}

	/**
	 * 修改会员积分明细
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		MemberPoint memberPoint = memberPointService.selectMemberPointById(id);
		mmap.put("memberPoint", memberPoint);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会员积分明细
	 */
	@RequiresPermissions("member:memberPoint:edit")
	@Log(title = "会员积分明细", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MemberPoint memberPoint) {
		return toAjax(memberPointService.updateMemberPoint(memberPoint));
	}
	
	/**
	 * 删除会员积分明细
	 */
	@RequiresPermissions("member:memberPoint:remove")
	@Log(title = "会员积分明细", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(memberPointService.deleteMemberPointByIds(ids));
	}
	
}
